<div class="layui-card-header layui-card">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>商户管理</cite></a>
        <a><cite>余额变更</cite></a>
    </div>
</div>


<div class="layui-fluid" id="LAY-app-message">
    <div class="layui-card">
        <div class="layui-tab layui-tab-brief">
            <ul class="layui-tab-title">
                <li class="layui-this">余额变更</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-form-item">
                    <blockquote class="layui-elem-quote" id="amountTip"></blockquote>
                </div>
                <div class="layui-tab-item layui-show">
                    <form class="layui-form center">
                        <div class="layui-form-item">
                            <label class="layui-form-label">商户ID</label>
                            <div class="layui-input-inline">
                                <input type="text" id="mchId" name="mchId" lay-verify="required" autocomplete="off" class="layui-input" disabled="disabled">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">账户类型</label>
                                <div class="layui-input-inline">
                                    <input type="radio" name="bizItem" value="10" title="账户余额" checked="checked">
                                    <input type="radio" name="bizItem" value="11" title="代付余额">
                                    <input type="radio" name="bizItem" value="12" title="冻结金额">
                                    <input type="radio" name="bizItem" value="13" title="保证金额">
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">变更金额(元)</label>
                            <div class="layui-input-inline">
                                <input type="text" required id="amount" name="amount"  lay-verify="required|number" placeholder="请输入金额" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">超级密码</label>
                            <div class="layui-input-inline">
                                <input type="password" required  name="password"  lay-verify="required|pass" placeholder="请输入超级密码" autocomplete="off" class="layui-input pwd">
                            </div>
                        </div>
                        <div class="layui-form-item ">
                            <div class="layui-input-block">
                                <button type="button" lay-submit lay-filter="btnCredit" class="layui-btn layui-btn-normal">增加金额</button>
                                <button type="button" lay-submit lay-filter="btnDebit" class="layui-btn layui-btn-danger">减少金额</button>
                                <a class="layui-btn" lay-href="merchant/list/">返回</a>
                            </div>
                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>
</div>

<script>
    layui.use(['form','util','admin'], function(){
       var form = layui.form
       ,$ = layui.$
       ,admin = layui.admin
       ,upload = layui.upload
       ,element = layui.element;

       element.render('breadcrumb', 'breadcrumb');//渲染导航信息
        var router = layui.router();
        var mchId = router.search.mchId;
        admin.req({
            type: 'get',
            url: layui.setter.baseUrl + '/account/get?mchId=' + mchId,
            error: function(err){
                layer.alert(err.msg,{title:'请求失败'})
            },
            success:function(res){
                if(res.code == 0 && res.data != null){
                    $('#mchId').val(res.data.mchId);
                    $('#amountTip').html(
                            "账户余额: <span style='color: green'>" + res.data.balance / 100 + "</span> 元 " +
                            "代付余额: <span style='color: green'>" + res.data.agentpayBalance / 100 + "</span> 元 " +
                            "冻结金额: <span style='color: red'>" + res.data.frozenMoney / 100 + "</span> 元 " +
                            "保证金额: <span style='color: red'>" + res.data.securityMoney / 100 + "</span> 元"
                    );
                }
            }
        });

       form.on('submit(btnCredit)', function(data){
           var amount = $("#amount").val();
           layer.confirm('确定为商户增加金额(' + amount + "元)么?", function(index){
               admin.req({
                   type: 'post',
                   url: layui.setter.baseUrl + '/account/credit',
                   data: data.field,
                   success: function(res){
                       if(res.code == 0){
                           layer.alert("加款成功!", {title: "提示"}, function(index){
                               layer.close(index);
                               location.hash = '/merchant/list/';
                           })
                       }
                   }
               });
               layer.close(index);
           });
           return false;//阻止跳转
        });

        form.on('submit(btnDebit)', function(data){
            var amount = $("#amount").val();
            layer.confirm('确定为商户减少金额(' + amount + "元)么?", function(index){
                admin.req({
                    type: 'post',
                    url: layui.setter.baseUrl + '/account/debit',
                    data: data.field,
                    success: function(res){
                        if(res.code == 0){
                            layer.alert("减款成功!", {title: "提示"}, function(index){
                                layer.close(index);
                                location.hash = '/merchant/list/';
                            })
                        }
                    }
                });
                layer.close(index);
            });
            return false;//阻止跳转
        });

        form.render();

    })
</script>